<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>轮播图案例</title>
</head>
<body>

<img src="img/banner_1.jpg" width="100%" id="img">

<script>
    var num = 1;
    function fun () {
        num++;
        if(num>3){
            num = 1;
        }
        var img = document.getElementById("img");
        img.src = "img/banner_" + num + ".jpg";
    }

    setInterval(fun,2000)

</script>

</body>
</html>